﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;

namespace Drifting.Graphics.PhysicalObjects
{
    public abstract class PhysicalObject : SceneDrawable
    {
        public Model Body;
        protected Matrix[] Body_AbsoluteMatrix;
        protected Matrix m_calibration;
        protected Matrix m_config;

        protected float body_scale = 0.0098f;

        public PhysicalObject()
        {
            m_config = Matrix.Identity;
            m_calibration = Matrix.Identity;
        }

        virtual public Matrix Config
        {
            get { return m_config; }
            set { m_config = value; }
        }

        virtual public void Draw(Matrix camera, Matrix projection)
        {
            foreach (ModelMesh mesh in Body.Meshes)
            {
                foreach (BasicEffect effect in mesh.Effects)
                {
                    effect.EnableDefaultLighting();
                    effect.View = camera;
                    effect.Projection = projection;
                    effect.World =

                        Body_AbsoluteMatrix[mesh.ParentBone.Index] *

                        Matrix.CreateScale(body_scale) *

                        m_calibration *

                        m_config;

                        // e.g. 
                        //Matrix.CreateRotationY((float)Math.PI/4) *  
                        //Matrix.CreateTranslation(1,0,4);

                }
                mesh.Draw();
            }
        }
    }
}
